//
//  MZMapViewController.m
//  Mehfile Zainab
//
//  Created by Sitara Badourali on 20/05/12.
//  Copyright (c) 2012 Mehfile Zainab. All rights reserved.
//

#import "MZMapViewController.h"
#import "MZMapViewAnnotation.h"

@implementation MZMapViewController

@synthesize mapView;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.

    self.mapView.delegate = self;     
    
    CLLocationCoordinate2D location;
	location.latitude = (double) 48.92752;
	location.longitude = (double) 2.387394;
    
	// Add the annotation to our map view
    NSString *subTitle =    @"19, avenue Gabriel Péri\n"
                            @"93120 La Courneuve";
	//MZMapViewAnnotation *newAnnotation = [[MZMapViewAnnotation alloc] initWithTitle:@"Mehfile Zainab" andCoordinate:location];
    MZMapViewAnnotation *newAnnotation = [[MZMapViewAnnotation alloc] initWithTitle:@"Mehfile Zainab" andSubTitle:subTitle andCoordinate:location];
	[self.mapView addAnnotation:newAnnotation];
	[newAnnotation release];
    
}

- (void)mapView:(MKMapView *)mv didAddAnnotationViews:(NSArray *)views
{
	MKAnnotationView *annotationView = [views objectAtIndex:0];
	id <MKAnnotation> mp = [annotationView annotation];
	MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance([mp coordinate], 1000, 1000);
	[mv setRegion:region animated:YES];
	[mv selectAnnotation:mp animated:YES];
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
    [mapView release];
    mapView = nil;
}

- (void)dealloc {
	[mapView release];
    [super dealloc];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

@end
